package com.sharemarking.wa.platform.mapper;

import com.sharemarking.wa.common.entity.Member;
import com.sharemarking.wa.platform.dto.dispather.DispatcherInfoDto;
import com.sharemarking.wa.platform.dto.dispather.DispatcherListDto;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * @author dxy
 */
@Repository
public interface DispatcherMapper {
    @Select("SELECT a.id AS dispatcherId,IFNULL(a.real_name,a.nick_name) AS name,a.mobile,a.create_date FROM sys_member a " +
            "LEFT JOIN sys_org_member b ON a.id = b.member_id WHERE b.org_id = #{orgId} AND a.role = 3 LIMIT #{pageIndex},#{pageSize}")
    List<DispatcherListDto> getDispatcherList(Map map);

    @Select("SELECT COUNT(*) FROM sys_member a " +
            "LEFT JOIN sys_org_member b ON a.id = b.member_id WHERE b.org_id = #{orgId} AND a.role = 3")
    Integer getDispatcherListTotal(Map map);

    @Update("UPDATE sys_member SET password = #{password},update_date = #{updateDate} WHERE id = #{id}")
    void resetPwd(Member member);

    @Update("UPDATE sys_member SET real_name = #{realName},mobile = #{mobile},update_date = #{updateDate} WHERE id = #{id}")
    void updateDispatcher(Member member);

    @Select("SELECT id AS dispatcherId,mobile,real_name AS name,create_date FROM sys_member WHERE id = #{id}")
    DispatcherInfoDto getDispatcherInfo(Integer id);

    @Delete("DELETE FROM sys_org_member WHERE member_id = #{id}")
    void delete(Integer id);
}
